<html>
<head><meta charset="utf-8"><title>fold by value · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html">fold by value</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="215673412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215673412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215673412">(Nov 05 2020 at 05:47)</a>:</h4>
<p>Oh right, I can't clone because it's a trait method, should I add <code>Clone</code> bounds everywhere? <span aria-label="confused" class="emoji emoji-1f615" role="img" title="confused">:confused:</span></p>



<a name="215673751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215673751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215673751">(Nov 05 2020 at 05:55)</a>:</h4>
<p><code>T: Clone</code>?</p>



<a name="215673753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215673753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215673753">(Nov 05 2020 at 05:55)</a>:</h4>
<p>Or are you talking about something different than the impl</p>



<a name="215673758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215673758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215673758">(Nov 05 2020 at 05:55)</a>:</h4>
<p>But, we could <em>maybe</em> just add a <code>: Clone</code> bound to <code>Foldable</code></p>



<a name="215673893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215673893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215673893">(Nov 05 2020 at 05:58)</a>:</h4>
<p><code>T: Clone</code>. Wait, that's not a trait method. But I get:</p>
<div class="codehilite"><pre><span></span><code>error[E0277]: the trait bound `G: Clone` is not satisfied
   --&gt; chalk-ir/src/lib.rs:115:45
    |
115 |   #[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit)]
    |                                               ^^^^ the trait `Clone` is not implemented for `G`
    |
   ::: chalk-ir/src/fold.rs:350:5
    |
350 | /     fn fold_with&lt;&#39;i&gt;(
351 | |         self,
352 | |         folder: &amp;mut dyn Folder&lt;&#39;i, I, TI&gt;,
353 | |         outer_binder: DebruijnIndex,
...   |
356 | |         I: &#39;i,
357 | |         TI: &#39;i;
    | |_______________- required by `fold::Fold::fold_with`
    |
    = note: required because of the requirements on the impl of `fold::Fold&lt;_I, _TI&gt;` for `&amp;G`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `G`
    |
115 | #[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, G: Clone, Visit)]
    |                                                 ^^^^^^^^^^
</code></pre></div>



<a name="215674043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215674043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215674043">(Nov 05 2020 at 06:02)</a>:</h4>
<p>That's when you add <code>T: Clone</code> for the <code> Fold&lt;I, TI&gt; for &amp;'a T</code> impl?</p>



<a name="215674170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215674170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215674170">(Nov 05 2020 at 06:04)</a>:</h4>
<p>Yes, <code>impl&lt;'a, T: Fold&lt;I, TI&gt; + Clone, I: Interner, TI: TargetInterner&lt;I&gt;&gt; Fold&lt;I, TI&gt; for &amp;'a T</code></p>



<a name="215674313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215674313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215674313">(Nov 05 2020 at 06:08)</a>:</h4>
<p>So that's <code>struct InEnvironment&lt;G: HasInterner&gt;</code></p>



<a name="215674500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215674500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215674500">(Nov 05 2020 at 06:13)</a>:</h4>
<p>If you just add <code>G: Clone</code>?</p>



<a name="215674506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215674506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215674506">(Nov 05 2020 at 06:13)</a>:</h4>
<p>(or is this a more widespread problem?)</p>



<a name="215674566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215674566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215674566">(Nov 05 2020 at 06:15)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error[E0277]: the trait bound `_U: Clone` is not satisfied
   --&gt; chalk-ir/src/lib.rs:115:45
    |
115 | #[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit)]
    |                                             ^^^^ the trait `Clone` is not implemented for `_U`
116 | #[allow(missing_docs)]
117 | pub struct InEnvironment&lt;G: HasInterner + Clone&gt; {
    |                                           ----- required by this bound in `InEnvironment`
    |
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
    |
115 | #[derive(Clone, Debug, PartialEq, Eq, Hash, Fold + Clone, Visit)]
    |                                                  ^^^^^^^
</code></pre></div>
<p>Wow, that's a new one :D</p>



<a name="215674847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215674847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215674847">(Nov 05 2020 at 06:23)</a>:</h4>
<p>I added more <code>Clone</code> bounds and now it complains about <code>Substitution::apply</code> moving out of a reference, which seems reasonable, but I don't understand why it worked before</p>



<a name="215675161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215675161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215675161">(Nov 05 2020 at 06:31)</a>:</h4>
<p><a href="https://github.com/rust-lang/chalk/pull/644/commits/e59b6e91d3355dde9f39f92f374f81e1fe592282">https://github.com/rust-lang/chalk/pull/644/commits/e59b6e91d3355dde9f39f92f374f81e1fe592282</a> only adds extra bounds, I don't understand why it makes the borrow checker complained, since the previous code compiled. It's as if something stopped being <code>Copy</code> because I asked it to be <code>Clone</code></p>



<a name="215675166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215675166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215675166">(Nov 05 2020 at 06:31)</a>:</h4>
<p>Maybe I could keep piling on more bounds, but if feels a bit wrong</p>



<a name="215695102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215695102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215695102">(Nov 05 2020 at 10:43)</a>:</h4>
<p>That <code>Fold + Clone</code> inside the derive looks wrong (the second time it's referencing line 115). Are we generating bounds wrong inside the derive macro, or is the error message wrong?</p>



<a name="215699309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/215699309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#215699309">(Nov 05 2020 at 11:29)</a>:</h4>
<p>The message was wrong. I updated the derive macro (it's on the branch), but other stuff is not compiling now, and it used to work before</p>



<a name="216928176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216928176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216928176">(Nov 16 2020 at 20:34)</a>:</h4>
<p>What's the status of your fold-by-value PR <span class="user-mention" data-user-id="216206">@lcnr</span> ?</p>



<a name="216928267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216928267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216928267">(Nov 16 2020 at 20:35)</a>:</h4>
<p>i have to rebase and still want to spend some time looking into why we have a 0.5% perf loss</p>



<a name="216928471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216928471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216928471">(Nov 16 2020 at 20:36)</a>:</h4>
<p>i hope i can get to it this week</p>



<a name="216928773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216928773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216928773">(Nov 16 2020 at 20:39)</a>:</h4>
<p>lol I just realized I'm the reviewer</p>



<a name="216928810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216928810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216928810">(Nov 16 2020 at 20:39)</a>:</h4>
<p>well yeah <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> you already approved it</p>



<a name="216928990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216928990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216928990">(Nov 16 2020 at 20:41)</a>:</h4>
<p>I was wondering because I was thinking about how to approach this idea of refactoring how rustc handles <code>ty::Param</code> and early bound regions</p>



<a name="216928994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216928994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216928994">(Nov 16 2020 at 20:41)</a>:</h4>
<p>and it is somewhat relevant</p>



<a name="216929011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216929011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216929011">(Nov 16 2020 at 20:41)</a>:</h4>
<p>not a big deal either way though, I'll be able to rebase over it</p>



<a name="216929019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216929019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216929019">(Nov 16 2020 at 20:41)</a>:</h4>
<p><code>&amp;self</code> is mildly more convenient to start probably</p>



<a name="216936640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216936640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216936640">(Nov 16 2020 at 21:43)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> the PR should be ready for merge</p>



<a name="216936711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216936711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216936711">(Nov 16 2020 at 21:43)</a>:</h4>
<p>wanna quickly look over it again or should I just reapprove myself?</p>



<a name="216936833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216936833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216936833">(Nov 16 2020 at 21:44)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> you can r=me</p>



<a name="216937027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/fold%20by%20value/near/216937027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/fold.20by.20value.html#216937027">(Nov 16 2020 at 21:46)</a>:</h4>
<p>will do<br>
<span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/144729-wg-traits/topic/fold.20by.20value/near/216928471">said</a>:</p>
<blockquote>
<p>i hope i can get to it this week</p>
</blockquote>
<p>tbh, if someone were to ping me every 2 hours rustc would be finished in less than a month</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>